package com.tom.controller;


import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.tom.domain.User;
import com.tom.exceptionHandler.ExceptionUtils;
import com.tom.userfallback.GetUserfallback;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RefreshScope //刷新配置
public class UserController {

    @Value("${temp.notify}")
    private Integer temp;
    @GetMapping("/getUser/{id}")
    // 限流降级
    @SentinelResource(value = "user",
            blockHandler = "exceptionHandler",
            blockHandlerClass = ExceptionUtils.class,
            fallback = "getUserfallback",
            fallbackClass = GetUserfallback.class
        )
    public User getUser(@PathVariable("id") Long id){
        return new User("你好",temp);
    }

//    public User getUserfallback(@PathVariable("id") Long id) {
//        return new User("熔断拖底数据",-1);
//    }
//    // 限流与阻塞处理 : 参数要和 被降级的方法参数一样
//    public User exceptionHandler(@PathVariable("id") Long id, BlockException ex) {
//        ex.printStackTrace();
//        return new User("限流了",-1);
//    }
}
